<template>
  <div id="employee-main-container" class="employee-index">
    <xr-header ft-top="0" placeholder="请输入员工姓名" show-search label="员工管理" @search="searchClick">
      <template slot="otherLabel">
        <i class="wk wk-icon-fill-help wk-help-tips" data-type="31" data-id="287" />
      </template>

      <template slot="bottom-ft">
        <el-button v-if="hasFilterContent" type="text" @click="resetFilter">清除筛选</el-button>
        <wk-popover-filter :width="popoverFilterWidth" :field-from.sync="filterObj" :field-list="filterList"
          :has-content="hasFilterContent" style="margin-right: 5px;" placement="bottom-end" @sure="refreshList"
          @reset="resetFilter" />
      </template>

      <template slot="ft">
        <template v-if="createAuth">
          <el-button type="primary" v-if="this.loginUser.isSuperAdmin" @click="empFieldDesensitizationClick">脱敏字段</el-button>
          <el-button type="primary" @click="empPushDataClick">员工数据同步</el-button>
          <el-button type="primary" @click="createClick">新建员工</el-button>
          <!--          <el-button-->
          <!--            plain-->
          <!--            @click="createFromDepClick">从组织架构中选择</el-button>-->
        </template>
        <el-dropdown v-if="headerMoreHandle.length > 0" trigger="click" style="margin-left: 5px;"
          @command="headerMoreHandleClick">
          <el-button icon="el-icon-more" />
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item v-for="(item, index) in headerMoreHandle" :key="index" :icon="item.icon"
              :command="item.type">{{
      item.name }}</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </template>
    </xr-header>
    <div class="crm-container">
      <flexbox class="filter">
<!--        <wk-border-menu v-model="tabType" :list="tabRightList"-->
<!--          :is-select="!!tabRightList.find(item => item.name == tabType)" style="flex: 3;" @select="tabClick" />-->
<!--        <wk-border-menu v-model="tabType" :list="tabLeftList"-->
<!--          :is-select="!!tabLeftList.find(item => item.name == tabType)" style="flex: 6;" @select="tabClick" />-->
<!--          <wk-border-menu v-model="tabType" :list="postStatusTotalList"-->
<!--                          :is-select="!!postStatusTotalList.find(item => item.name == tabType)" style="flex: 6;" @select="tabClick" />-->
      </flexbox>
      <xr-table-header v-if="selectionList.length > 0" :handles="tabelHandles" :selects="selectionList"
        @command="handleCommand">
        <!-- <el-tabs v-model="tabType" style="width: 100%;margin-bottom: -8px;" @tab-click="createSaveSuccess">
          <el-tab-pane
            v-for="tab in tabList"
            :key="tab.name"
            :name="tab.name">
            <span slot="label">{{ tab.label }}<span v-if="tab.num > 0" style="margin-left: 5px;" class="tab-pane-num">{{ tab.num }}</span></span>
          </el-tab-pane>
        </el-tabs> -->
      </xr-table-header>
      <el-table id="crm-table" v-loading="loading" :row-height="44" :data="list" :height="tableHeight"
        :cell-class-name="cellClassName" :class="WKConfig.tableStyle.class" :stripe="WKConfig.tableStyle.stripe"
        use-virtual class="n-table--border el-table-header--white" highlight-current-row style="width: 100%;"
        @row-click="handleRowClick" @header-dragend="handleHeaderDragend" @selection-change="handleSelectionChange"
        @sort-change="sortChange">
        <el-table-column v-if="deleteAuth || multiInsuredShow" show-overflow-tooltip fixed type="selection"
          align="center" width="55" />
        <el-table-column v-for="(item, index) in showFieldList" :key="index" :fixed="index == 0" :prop="item.fieldName"
          :label="item.name" :sortable="item.sortable" :min-width="item.width" :formatter="fieldFormatter"
          show-overflow-tooltip >
            <template slot-scope="scope">
              <div v-html="fieldFormatterNew(scope.row,item.fieldName)"></div>
            </template>
        </el-table-column>
        <el-table-column />
        <el-table-column v-if="moreHandleShow" label="操作" fixed="right" width="100">
          <template slot-scope="scope">
            <el-dropdown v-if="getRowDropdownShow(scope.row)" trigger="click"
              @command="handleTypeClick($event, scope.row)">
              <i class="el-icon-more table-more" />
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-for="(item, index) in getRowDropdownItems(scope.row)" :key="index" :icon="item.icon"
                  :command="item.command">{{ item.label }}</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
        <el-table-column />
        <!-- <el-table-column
          :resizable="false"
          fixed="right"
          width="40">
          <template
            slot="header"
            slot-scope="slot">
            <wk-field-set
              :loading="fieldSetLoading"
              :fields="setFieldList"
              @save="fieldSetSave" />
          </template>
        </el-table-column> -->
        <wk-field-set slot="other" class="field-set-wrap" :loading="fieldSetLoading" :fields="setFieldList"
          @save="fieldSetSave" />
      </el-table>
      <div class="p-contianer">
        <el-pagination :current-page="currentPage" :page-sizes="pageSizes" :page-size.sync="pageSize" :total="total"
          class="p-bar" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </div>
    <employee-detail v-if="showDview" :id="rowID" :search="search"  :user-info="userInfo" @handle="detailHandle"
      @close="showDview = false" />
    <employee-create-view v-if="isCreate" :create-type="createType" :detail="handleRowData" @success="createSaveSuccess"
      @close="isCreate = false" />

    <form-add-dialog ref="formAdddialog" :title="formAddTitle" :form.sync="formAddForm" :rules="formAddRules"
      :fields="formAddFields" :visible.sync="formAddDialogShow" :help-obj="helpObj" @pass="formAddPass"
      @change="formChange" />

    <update-scheme-dialog :id="handleRowData ? handleRowData.employeeId : ''" :list="selectionList"
      :type="updateSchemeType" :visible.sync="updateSchemeDialogShow" @change="getList" />

    <give-up-leave-dialog :id="handleRowData ? handleRowData.employeeId : ''" :visible.sync="giveUpLeaveShow"
      @change="refreshPageData" />

    <dep-add-employ-dialog v-if="depAddEmplogyShow" :visible.sync="depAddEmplogyShow" @change="refreshPageData" />
    <el-dialog title="提示" :visible.sync="showPreview" width="900px" :before-close="handleClose">
      <el-button type="primary" @click="fileOperate(2, handleRowData)">导出word</el-button>
      <el-button type="warning" @click="fileOperate(3, handleRowData)">导出PDF</el-button>
      <div class="docWrap" style="margin-top: 20px;">
        <div id="pdfDom" ref="file" />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showPreview = false">取 消</el-button>
        <el-button type="primary" @click="showPreview = false">确 定</el-button>
      </span>
    </el-dialog>

    <!--  脱敏字段页面  -->
    <el-dialog :title="desensitization.title" :visible.sync="desensitization.open" width="1000px"
               v-if="desensitization.open" append-to-body>
      <create-sections v-for="(item, key, index) in desensitization.list" :key="index" :list="item" :index="index"
                       :title="key">
        <div style="display: flex;flex-wrap:wrap">
          <div v-for="(obj, k) in item" style="margin: 20px">
            <el-switch
                v-model="obj.isEncrypt"
                active-text=""
                :active-value="desensitization.activeValue"
                :inactive-value="desensitization.inactiveValue"
                :inactive-text="obj.fieldLabel">
            </el-switch>
          </div>
        </div>
      </create-sections>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitDesensitization">确 定</el-button>
        <el-button @click="desensitization.open = false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  hrmEmployeeQueryPageListAPI,
  hrmEmployeeFieldListHeadsAPI,
  hrmEmployeeQueryStatusNumAPI,
  hrmEmployeeDeleteByIdsAPI,
  hrmEmployeeSetBecomeAPI,
  hrmEmployeeSetChangePostAPI,
  hrmEmployeeSetPromotionAPI,
  hrmEmployeeFieldUpdateConfigAPI,
  hrmEmployeeFieldUpdateWidthAPI,
  hrmEmployeeExportAPI,
  hrmEmployeeDownloadExportAPI,
  hrmEmployeeUploadExportAPI,
  hrmEmployeePersonalInfoAPI,
  empDeptPushDataAPI,
  hrmQueryFieldGroupAPI,
  hrmSetFieldListAPI,
  hrmManageEmployeeIdListAPI,
  hrmEmployeePushDataByIdsAPI,
  hrmEmployeeDetailByEmpIdAPI,
  hrmEmployeePostLevelAuditAPI,
  hrmEmployeeGzwEmployeeSyncAPI,
  hrmEmployeeGzwPostSyncAPI,
  hrmEmployeeGzwEducationSyncAPI,
  hrmEmployeeGzwWorkSyncAPI,
} from '@/api/hrm/employee'
import {
  hrmDeptQueryTreeListAPI
} from '@/api/hrm/dept'
import {
  hrmEmployeePostAddLeaveAPI
} from '@/api/hrm/employeePost'
import { exportWordImage, getWordImage, exportPdf, exportWord } from '@/utils/exportFile'
import XrHeader from '@/components/XrHeader/Search'
import XrTableHeader from '@/components/XrTableHeader'
import WkPopoverFilter from '@/components/NewCom/WkPopoverFilter'
import WkFieldSet from '@/components/NewCom/WkFieldSet'
import EmployeeCreateView from './components/EmployeeCreateView'
import EmployeeDetail from './EmployeeDetail'
import FormAddDialog from './components/FormAddDialog'
import UpdateSchemeDialog from './components/UpdateSchemeDialog'
import GiveUpLeaveDialog from './components/GiveUpLeaveDialog'
import DepAddEmployDialog from './components/DepAddEmployDialog' // 从系统管理导入员工
import WkBorderMenu from '../components/WkBorderMenu'

import { mapGetters } from 'vuex'
import {employeeModel, educationModel, officialModel, changePostModel, changePostLevelModel} from './model/employee'
import employeePost from './model/employeePost'
import employeeContract from './model/employeeContract'
import {objDeepCopy, downloadExcelWithResData, getImageData} from '@/utils'
import {Message} from "element-ui";
import CreateSections from "@/components/CreateSections.vue";
import {queryLoginEmployeeAPI} from '@/api/hrm/employee'

export default {
  name: 'EmployeeIndex',
  components: {
    CreateSections,
    XrHeader,
    XrTableHeader,
    EmployeeCreateView,
    EmployeeDetail,
    WkPopoverFilter,
    WkFieldSet,
    FormAddDialog,
    UpdateSchemeDialog,
    GiveUpLeaveDialog,
    DepAddEmployDialog,
    WkBorderMenu
  },
  beforeRouteUpdate(to, from, next) {
    const query = this.$route.query
    if (query.depAddEmplogyShow) {
      this.depAddEmplogyShow = true
    }
    next()
  },
  data() {
    return {
      manageEmployeeIdList: [],
      fieldGroup: {},
      desensitization: {
        open: false,
        activeValue: 1,
        inactiveValue: 0,
        title: "脱敏列表",
        list: [],
      },
      loginUser: {
        isAdmin: false,
      },
      showPreview: false,
      wordType: 1,		// 1是履历表，2是干部任免表
      showTimeResume: false, // 时间履历弹窗
      loading: false, // 加载动画
      createType: '', // 创建类型
      isCreate: false, // 是创建
      tableHeight: document.documentElement.clientHeight - 345, // 表的高度
      list: [],
      fieldList: [],
      // 性别、出生日期、年龄、入职日期、转正日期、部门、工号、生日
      sortFields: ['sex', 'dateOfBirth', 'age', 'entryTime', 'becomeTime', 'fieldName', 'jobNumber', 'birthday', 'deptId'],
      sortData: {}, // 字段排序
      currentPage: 1,
      pageSize: 15,
      pageSizes: [15, 30, 60, 100],
      total: 0,
      search: '', // 搜索内容
      queryParams: {}, // query 传入参数
      // 筛选宽
      popoverFilterWidth: document.documentElement.clientWidth - 80,
      tabType: '12',
      // 员工状态 1正式 2试用 3实习 4兼职 5劳务 6顾问 7返聘 8外包 13待离职 14待入职  15已离职
      tabLeftList: [
        {
          label: '劳动合同工',
          name: '1',
          num: 0
        },
        {
          label: '劳务派遣',
          name: '2',
          num: 0
        },
        {
          label: '劳务外包',
          name: '3',
          num: 0
        },
        {
          label: '临时工',
          name: '4',
          num: 0
        },
        {
          label: '其他',
          name: '5',
          num: 0
        },
      ],
        postStatusTotalList: [{
            label: '在岗',
            name: '6',
            num: 0
        }, {
            label: '离退休',
            name: '7',
            num: 0
        }, {
            label: '内退不在岗',
            name: '8',
            num: 0
        }, {
            label: '其他',
            name: '9',
            num: 0
        }
        ],
      // tabCenterList: [{
      //   label: '试用',
      //   name: '2',
      //   num: 0
      // }, {
      //   label: '正式',
      //   name: '1',
      //   num: 0
      // }],
      tabRightList: [{
        label: '总人数',
        name: '21',
        num: 0
      }, {
        label: '男',
        name: '22',
        num: 0
      }, {
        label: '女',
        name: '23',
        num: 0
      }],
      /** 控制详情展示 */
      rowID: '', // 行信息
      showDview: false,
      // 高级筛选
      filterObj: {}, // 筛选确定数据
      filterList: [
        //   {
        //   name: '姓名',
        //   field: 'employeeName',
        //   formType: 'text',
        //   setting: []
        // },
        {
          name: '手机号码',
          field: 'mobile',
          formType: 'text',
          setting: []
        }, {
          name: '性别',
          field: 'sex',
          formType: 'radio',
          setting: [{
            label: '男',
            value: 1
          }, {
            label: '女',
            value: 2
          }]
        }, {
          name: '工作地点',
          field: 'workAddress',
          formType: 'text',
          setting: []
        }, {
          name: '用工形式',
          field: 'workType',
          formType: 'select',
          setting: [{
            label: '劳动合同工',
            value: '劳动合同工'
          }, {
            label: '劳务派遣',
            value: '劳务派遣'
          }, {
            label: '劳务外包',
            value: '劳务外包'
          }, {
            label: '临时工',
            value: '临时工'
          },{
            label: '退休返聘',
            value: '退休返聘'
          },{
            label: '外部董事',
            value: '外部董事'
          }]
        }, {
          name: '在岗状态',
          field: 'entryStatus',
          formType: 'select',
          setting: [{
            label: '在岗',
            value: '在岗'
          }, {
            label: '离休',
            value: '离休'
          }, {
            label: '退休',
            value: '退休'
          }, {
            label: '内退',
            value: '内退'
          }, {
            label: '不在岗',
            value: '不在岗'
          }, {
            label: '借调',
            value: '借调'
          }, {
            label: '跟班学习',
            value: '跟班学习'
          }, {
            label: '离职',
            value: '离职'
          }]
        }, {
          name: '入职日期',
          field: 'entryTime',
          formType: 'dateRange',
          setting: []
        }, {
          name: '职务',
          field: 'jobTitle',
          formType: 'text',
          setting: []
        }, {
          name: '身份证号',
          field: 'idNumber',
          formType: 'text',
          setting: []
        }, {
          name: '转正日期',
          field: 'becomeTime',
          formType: 'dateRange',
          setting: []
        },
        //  {
        //   name: '工号',
        //   field: 'jobNumber',
        //   formType: 'text',
        //   setting: []
        // },
        {
          name: '部门',
          field: 'deptId',
          formType: 'structure',
          props: {
            dataType: 'hrm'
          },
          request: hrmDeptQueryTreeListAPI,
          setting: []
        }, {
          name: '年龄',
          field: 'age',
          formType: 'range',
          precision: 0,
          setting: []
        }, {
          name: '外语水平',
          field: 'languageLevel',
          formType: 'text',
          setting: []
        },
        {
          name: '专业技术资格',
          field: 'technicalName',
          formType: 'autocomplete',
          setting: [{
            label: '高教教师',
            value: '高教教师'
          }, {
            label: '主任药师',
            value: '主任药师'
          }, {
            label: '国家级教练',
            value: '国家级教练'
          }, {
            label: '一级特技美术设计师',
            value: '一级特技美术设计师'
          }, {
            label: '一级律师',
            value: '一级律师'
          }, {
            label: '高级讲师',
            value: '高级讲师'
          }]
        },
        // {
        //   name: '职称',
        //   field: 'fieldFmpdum',
        //   formType: 'select',
        //   setting: [
        //     {"label":"正高级","value":1},
        //     {"label":"副高级","value":2},
        //     {"label":"中级","value":3},
        //     {"label":"初级","value":4},
        //     {"label":"无","value":5},
        //     ]
        // },
        {
          name: '最高学历',
          field: 'highestEducation',
          formType: 'select',
          setting: [
            { 'label': '小学', 'value': 1 },
            { 'label': '初中', 'value': 2 },
            { 'label': '高中', 'value': 3 },
            { 'label': '中专', 'value': 4 },
            { 'label': '大专', 'value': 5 },
            { 'label': '大学', 'value': 6 },
            { 'label': '硕士研究生', 'value': 7 },
            { 'label': '博士研究生', 'value': 8 },
            { 'label': '无', 'value': 0 }]
        }, {
          name: '职位层级',
          field: 'postLevel',
          formType: 'select',
          setting: [
            { label: "集团高管正职", value: "集团高管正职" },
            { label: "集团高管副职", value: "集团高管副职" },
            { label: "集团高管助理", value: "集团高管助理" },
            { label: "集团副总师", value: "集团副总师" },
            { label: "集团中层正职", value: "集团中层正职" },
            { label: "集团中层副职", value: "集团中层副职" },
            { label: "集团中层助理", value: "集团中层助理" },
            { label: "集团员工", value: "集团员工" },
            { label: "一级公司高管正职", value: "一级公司高管正职" },
            { label: "一级公司高管副职", value: "一级公司高管副职" },
            { label: "一级公司高管助理", value: "一级公司高管助理" },
            { label: "一级公司副总师", value: "一级公司副总师" },
            { label: "一级公司中层正职", value: "一级公司中层正职" },
            { label: "一级公司中层副职", value: "一级公司中层副职" },
            { label: "一级公司中层助理", value: "一级公司中层助理" },
            { label: "一级公司员工", value: "一级公司员工" },
            { label: "二级公司高管正职", value: "二级公司高管正职" },
            { label: "二级公司高管副职", value: "二级公司高管副职" },
            { label: "二级公司高管助理", value: "二级公司高管助理" },
            { label: "二级公司中层正职", value: "二级公司中层正职" },
            { label: "二级公司中层副职", value: "二级公司中层副职" },
            { label: "二级公司中层助理", value: "二级公司中层助理" },
            { label: "二级公司员工", value: "二级公司员工" },
            { label: "三级公司高管正职", value: "三级公司高管正职" },
            { label: "三级公司高管副职", value: "三级公司高管副职" },
            { label: "三级公司高管助理", value: "三级公司高管助理" },
            { label: "三级公司中层正职", value: "三级公司中层正职" },
            { label: "三级公司中层副职", value: "三级公司中层副职" },
            { label: "三级公司中层助理", value: "三级公司中层助理" },
            { label: "三级公司员工", value: "三级公司员工" },
            { label: "四级公司高管正职", value: "四级公司高管正职" },
            { label: "四级公司高管副职", value: "四级公司高管副职" },
            { label: "四级公司高管助理", value: "四级公司高管助理" },
            { label: "四级公司中层正职", value: "四级公司中层正职" },
            { label: "四级公司中层副职", value: "四级公司中层副职" },
            { label: "四级公司中层助理", value: "四级公司中层助理" },
            { label: "四级公司员工", value: "四级公司员工" },
          ]
        },
        {
          name: '职称级别',
          field: 'technicalLevel',
          formType: 'select',
          setting: [{
            label: '正高级',
            value: '正高级'
          }, {
            label: '副高级',
            value: '副高级'
          }, {
            label: '中级',
            value: '中级'
          }, {
            label: '助理级',
            value: '助理级'
          }, {
            label: '员级',
            value: '员级'
          }, {
            label: '无',
            value: '无'
          }]
        },
        {
          name: '专技等级',
          field: 'specialWorkerLevel',
          formType: 'select',
          setting: [{
            label: '高级技师',
            value: '高级技师'
          }, {
            label: '技师',
            value: '技师'
          }, {
            label: '高级工',
            value: '高级工'
          }, {
            label: '中级工',
            value: '中级工'
          }, {
            label: '初级工',
            value: '初级工'
          }]
        },
        {
          name: '专业',
          field: 'major',
          formType: 'text',
          setting: []
        },
        {
          name: '教育形式',
          field: 'teachingMethods',
          formType: 'select',
          clearable: true,
          setting: [{
            label: '普通全日制',
            value: 1
          }, {
            label: '脱产',
            value: 2
          }, {
            label: '远程教育',
            value: 3
          }, {
            label: '自学考试',
            value: 4
          }, {
            label: '函授',
            value: 5
          }, {
            label: '业余',
            value: 6
          }, {
            label: '非全日制',
            value: 7
          }]
        },
        {
          name: '学校名称',
          field: 'schoolName',
          formType: 'text',
          setting: []
        },
      ],
      selectionList: [], // 勾选数据 用于全局导出
      // 弹窗添加
      formAddType: '', // 事件类型
      formAddForm: {},
      formAddRules: {},
      formAddFields: [],
      formAddDialogShow: false,
      // 编辑详情
      // 需要编辑的员工详情
      handleRowData: null,
      fieldSetLoading: false,
      // 修改社保
      updateSchemeType: 1, // 1 一个  2  多个
      updateSchemeDialogShow: false,
      // 放弃离职
      giveUpLeaveShow: false,
      // 从系统管理导入员工
      depAddEmplogyShow: false,
      helpObj: {
        dataType: 31,
        dataId: 288
      }
    }
  },
  computed: {
    ...mapGetters([
      'hrm',
      'hrmUserType',
      'userInfo'
    ]),
    // 员工权限
    employeeAuth() {
      return this.hrm.employee
    },

    // 员工新建
    createAuth() {
      return this.employeeAuth && this.employeeAuth.save
    },

    // 删除权限
    deleteAuth() {
      return this.employeeAuth && this.employeeAuth.delete
    },

    // 导出权限
    excelexportAuth() {
      return this.employeeAuth && this.employeeAuth.excelexport
    },

    // 导入权限
    excelimportAuth() {
      return this.employeeAuth && this.employeeAuth.excelimport
    },

    // 员工详情
    detailAuth() {
      return this.employeeAuth && this.employeeAuth.read
    },

    // 更多操作展示
    moreHandleShow() {
      return this.employeeAuth.confirmEntry ||
        this.employeeAuth.againOnboarding ||
        this.employeeAuth.become ||
        this.employeeAuth.changePost ||
        this.employeeAuth.promotion ||
        this.employeeAuth.setInsured ||
        this.employeeAuth.cancelLevel ||
        this.employeeAuth.leave
    },

    /**
     * 头部更多操作
     */
    headerMoreHandle() {
      const temps = []
      if (this.excelimportAuth) {
        temps.push({ type: 'import', name: '导入', icon: 'wk wk-import' })
      }

      if (this.excelexportAuth) {
        temps.push({ type: 'export', name: '导出', icon: 'wk wk-export' })
      }
      temps.push({type: 'employeeSync', name: '国资委人员同步', icon: 'wk wk-icon-user'})
      temps.push({type: 'postSync', name: '国资委岗位同步', icon: 'wk wk-icon-user'})
      temps.push({type: 'educationSync', name: '国资委教育同步', icon: 'wk wk-icon-user'})
      temps.push({type: 'workSync', name: '国资委工作同步', icon: 'wk wk-icon-user'})

      return temps
    },

    // 操作
    tabelHandles() {
      const temps = []
      if (this.deleteAuth) {
        temps.push({
          label: '删除',
          command: 'delete',
          icon: 'wk wk-delete'
        })
      }

      if (this.multiInsuredShow) {
        temps.push({
          label: '参保方案',
          command: 'security',
          icon: 'wk wk-approval-9'
        })
      }

      if (this.excelexportAuth) {
        temps.push({
          label: '导出选中',
          command: 'export',
          icon: 'wk wk-export'
        })
      }
        temps.push({
            label: '数据推送',
            command: 'pushData',
            icon: 'wk wk-icon-user'
        })
      return temps
    },

    // 多员工社保曹组哦权限
    multiInsuredShow() {
      return this.employeeAuth.setInsured && (
        this.tabType == '12' ||
        this.tabType == '2' ||
        this.tabType == '1'
      )
    },

    // 有筛选内容
    hasFilterContent() {
      if (this.filterObj) {
        let hasContent = false
        const keys = Object.keys(this.filterObj)
        for (let index = 0; index < keys.length; index++) {
          const key = keys[index]
          if (this.filterObj[key] != '' &&
            this.filterObj[key] != [] &&
            this.filterObj[key] != null &&
            this.filterObj[key] != undefined) {
            hasContent = true
          }
        }
        return hasContent
      }
      return false
    },

    // 表头
    showFieldList() {
      return this.fieldList.filter(item => item.isHide != 1)
    },

    // 设置字段
    setFieldList() {
      const showList = []
      const hideList = []
      for (let index = 0; index < this.fieldList.length; index++) {
        const item = objDeepCopy(this.fieldList[index])
        item.left = ''
        item.center = ''
        item.right = ''
        item.check = item.isHide != 1
        if (item.check) {
          showList.push(item)
        } else {
          hideList.push(item)
        }
      }

      return showList.concat(hideList)
    },

    formAddTitle() {
      return {
        confirm: '',
        again: '',
        official: '办理转正',
        'change-post': '人员调动',
        'change-level': '晋升/降级',
        security: '',
        'give-up-leave': '',
        leave: '办理离职',
        'post-adjust':'职位层级调整',
      }[this.formAddType]
    }
  },
  created() {
    window.onresize = () => {
      this.tableHeight = document.documentElement.clientHeight - (this.selectionList.length > 0 ? 395 : 345)
    }

    // 监听导入
    this.$bus.on('import-crm-done-bus', () => {
      this.refreshPageData()
    })

    // 加入query筛选 workbench 工作台
    const query = this.$route.query
    if (query) {
      if (query.workbench == 'filter') {
        const queryParams = this.$route.query
        if (queryParams && queryParams.tabType) {
          this.tabType = queryParams.tabType
        } else {
          this.tabType = ''
          this.queryParams = queryParams
          delete this.queryParams['workbench']
        }
      } else if (query.depAddEmplogyShow) {
        this.depAddEmplogyShow = true
      }
    }

    this.getFieldList()
    this.refreshList()
    this.getTabsNum()
    this.getManageEmployeeIdList()
    this.getLoginUser()
  },
  mounted() {
    // 路由配置事件
    this.initTask()
  },
  beforeDestroy() {
    this.$bus.off('import-crm-done-bus')
  },
  methods: {
    /**
     * 获取当前登录人信息
     */
    getLoginUser() {
      queryLoginEmployeeAPI()
        .then(res => {
          this.loginUser = res.data;
        })
        .catch(() => {
        })
    },
    /**
     * 获取领导班子工id列表
     */
    getManageEmployeeIdList() {
      hrmManageEmployeeIdListAPI(82200023)
          .then(res => {
            this.manageEmployeeIdList = res.data.manageList;
            this.fieldGroup = res.data.fieldGroup;
          })
          .catch(() => {
          })
    },
    /**
     * 列表数据脱敏
     */
    getEncryptObj(data) {
      let resData = data || []
      let fieldList = this.fieldGroup[0];
      if (!fieldList || fieldList.length <= 0) return
      for (let index = 0; index < resData.length; index++) {
        const item = resData[index]
        if (this.manageEmployeeIdList.findIndex(i => i == item.employeeId) >= 0){
          //邻导班子员工
          for (let key in item) {
            if (fieldList.findIndex(item => item == key) >= 0) {
              item[key] = "*****";
            }
          }
        }
      }
    },
    /**
     * 获取字段列表
     */

    /**
     * 刷新当前页面信息
     */
    refreshPageData() {
      // 刷新当前人状态
      this.$store.dispatch('GetHrmUserInfo')
      this.getList()
      this.getTabsNum()
    },

    /**
     * 获取tab 数量
     */
    getTabsNum() {
      const params = {
        status: this.tabType
      }
      for (const key in this.filterObj) {
        params[key] = this.filterObj[key]
      }

      for (const key in this.queryParams) {
        params[key] = this.queryParams[key]
      }
      // if (!(key == 'age' && this.filterObj.age[0] == 0 && this.filterObj.age[1] == 0)){
      //     params[key] = this.filterObj[key]
      // }
      // hrmEmployeeQueryStatusNumAPI(params)
      //   .then(res => {
      //     const data = res.data || {}
      //     this.tabLeftList.forEach(item => {
      //       item.num = data[parseInt(item.name)]
      //     })
      //     this.tabRightList.forEach(item => {
      //       item.num = data[parseInt(item.name)]
      //     })
      //       this.postStatusTotalList.forEach(item => {
      //           item.num = data[parseInt(item.name)]
      //       })
      //   })
      //   .catch(() => {
      //   })
    },

    /**
     * tab点击
     */
    tabClick(tab) {
      this.queryParams = {} // 切换置空
      this.refreshList()
    },

    /**
     * 高级筛选
     */
    resetFilter() {
      this.filterObj = {}
      this.refreshList()
    },

    /**
     * 新建
     */
    createClick() {
      this.handleRowData = null
      this.createType = 'new'
      this.isCreate = true
    },

    /**
     * 员工字段脱敏
     */
    empFieldDesensitizationClick() {
      this.desensitization.open = true;
      this.desensitization.list = [];
      hrmQueryFieldGroupAPI().then(res => {
        this.desensitization.list = res.data;
      }).catch(() => {
      })
    },

    /**
     * 提交自定义脱敏
     */
    submitDesensitization(){
      let fieldList = [];
      for (let key in this.desensitization.list) {
        this.desensitization.list[key].forEach(item => {
          fieldList.push(item)
        })
      }
      hrmSetFieldListAPI(fieldList).then(res => {
        Message({
          message: '提交成功',
          type: 'success'
        })
        this.getList();
        this.desensitization.open = false;
      }).catch(() => {
      })
    },

    /**
     * 员工数据同步
     */
    empPushDataClick(){
      this.$confirm('是否把员工数据同步到市政通系统', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          empDeptPushDataAPI().then(res => {
            Message({
              message: '同步成功',
              type: 'success'
            })
          })
            .catch(() => {
            })
        })
        .catch(() => {
        })
    },

    /**
     * 新建从组织
     */
    createFromDepClick() {
      this.depAddEmplogyShow = true
    },

    /**
     * 创建成功
     */
    createSaveSuccess() {
      this.getTabsNum()
      this.refreshList()
    },

    /**
     * 搜索
     */
    searchClick(search) {
      this.search = search
      this.refreshList()
    },

    /**
     * 详情操作
     */
    detailHandle(data) {
      if (data.type === 'delete') {
        // 刷新当前人状态
        this.$store.dispatch('GetHrmUserInfo')
        this.showDview = false
      }
      this.getTabsNum()
      this.getList()
    },
    handleClose() {
      this.showPreview = false
    },
    /**
     * 获取表头展示字段
     */
    getFieldList() {
      hrmEmployeeFieldListHeadsAPI().then(res => {
        const fieldList = res.data || []
        fieldList.forEach(item => {
          item.sortable = this.sortFields.includes(item.fieldName)
        })
        this.fieldList = fieldList
      }).catch(() => {
      })
    },

    /**
     * 刷新
     */
    refreshList() {
      this.handleCurrentChange(1)
      this.getTabsNum()
    },

    /**
     * 更改每页展示数量
     */
    handleSizeChange(val) {
      this.pageSize = val
      this.getList()
    },

    /**
     * 更改当前页数
     */
    handleCurrentChange(val) {
      this.currentPage = val
      this.getList()
    },

    /**
     * 字段排序
     */
    sortChange(column, prop, order) {
      this.currentPage = 1
      this.sortData = column
      this.getList()
    },

    /**
     * 列表数据
     */
    getList() {
      this.loading = true
      const params = {
        page: this.currentPage,
        limit: this.pageSize,
        isHighlight: 1,
        employeeName: this.search,
        status: this.tabType
      }

      for (const key in this.filterObj) {
        params[key] = this.filterObj[key]
      }

      for (const key in this.queryParams) {
        params[key] = this.queryParams[key]
      }
      // if (!(key == 'age' && this.filterObj.age[0] == 0 && this.filterObj.age[1] == 0)){
      //     params[key] = this.filterObj[key]
      // }
      if (this.sortData.order) {
        params.sortField = this.sortData.prop
        params.order = this.sortData.order == 'ascending' ? 2 : 1
      }

      hrmEmployeeQueryPageListAPI(params)
        .then(res => {
          this.getManageEmployeeIdList();
          this.list = res.data.list
          // this.getEncryptObj(this.list);
          this.total = res.data.totalRow
          if (res.data.totalRow && Math.ceil(res.data.totalRow / this.pageSize) < this.currentPage && this.currentPage > 1) {
            this.currentPage = this.currentPage - 1
            this.getList()
          } else {
            this.total = res.data.totalRow
            this.loading = false
          }

          this.$nextTick(() => {
            const warpDom = document.querySelector('.el-table__body-wrapper')
            warpDom.scrollTop = 1
            if (warpDom.scrollLeft != 0) {
              warpDom.scrollLeft = warpDom.scrollLeft - 1
            }
          })
          this.loading = false
        })
        .catch(() => {
          this.loading = false
        })
    },

    /**
     * 格式化字段
     */
    fieldFormatter(row, column) {
      let fieldList = this.fieldGroup[0] || [];
      if (this.manageEmployeeIdList.findIndex(i => i == row.employeeId) >= 0
          && fieldList.findIndex(field => field == column.property) >= 0) {
        return "*****";
      }
      const valueObj = employeeModel[`${column.property}Value`]
      if (valueObj) {
        return valueObj[row[column.property]] || '/'
      } else if (column.property == 'highestEducation') {
        return educationModel.educationValue[row[column.property]] || '-'
      } else if (column.property == 'contractType') {
        return employeeContract.contractTypeValue[row.contractType] || '-'
      } else if (column.property == 'term') {
        return employeeContract.termValue[row.term] || '--'
      } else if (column.property == 'dept') {
        return row.deptName
      } else if (column.property == 'org') {
        return row.orgName
      } else if (column.property == 'parentId') {
        return row.parentName
      } else if (column.property == 'channelId') {
        return row.channelName
      } else {
        return row[column.property] && row[column.property] !== undefined ? row[column.property] : '-'
      }
    },

    /**
     * 格式化字段
     */
    fieldFormatterNew(row, column) {
      let fieldList = this.fieldGroup[0] || [];
      if (this.manageEmployeeIdList.findIndex(i => i == row.employeeId) >= 0
          && fieldList.findIndex(field => field == column) >= 0) {
        return "*****";
      }
      if (column == 'sex'){
        return row.sexCn
      }
      const valueObj = employeeModel[`${column}Value`]
      if (valueObj) {
        return valueObj[row[column]] || '/'
      } else if (column == 'highestEducation') {
        return educationModel.educationValue[row[column]] || '-'
      } else if (column == 'contractType') {
        return employeeContract.contractTypeValue[row.contractType] || '-'
      } else if (column == 'term') {
        return employeeContract.termValue[row.term] || '--'
      } else if (column == 'dept') {
        return row.deptName
      } else if (column == 'org') {
        return row.orgName
      } else if (column == 'parentId') {
        return row.parentName
      } else if (column == 'channelId') {
        return row.channelName
      } else {
        return row[column] && row[column] !== undefined ? row[column] : '-'
      }
    },

    /**
     * 通过回调控制class
     */
    cellClassName({ row, column, rowIndex, columnIndex }) {
      if (this.detailAuth && column.property == 'employeeName') {
        return 'can-visit--underline'
      } else {
        return ''
      }
    },

    /**
     * 列表操作
     */
    handleCommand(command) {
      if (command === 'delete') {
        this.$confirm('确定要删除吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            hrmEmployeeDeleteByIdsAPI(this.selectionList.map(item => item.employeeId))
              .then(res => {
                this.$message({
                  type: 'success',
                  message: '删除成功'
                })
                this.getTabsNum()
                this.getList()
              })
              .catch(() => { })
          })
          .catch(() => { })
      } else if (command === 'security') {
        this.updateSchemeType = 2
        this.updateSchemeDialogShow = true
      } else if (command === 'export') {
        this.loading = true
        hrmEmployeeExportAPI({
          employeeIds: this.selectionList.map(item => item.employeeId)
        }).then(res => {
          // 获取响应头中的密码
          console.log(res.headers)
          const password = res.headers["content-description"]
          if (password) {
            this.$alert(`导出文件的密码为: ${password}`, '导出提示', {
              confirmButtonText: '确定',
              callback: () => {
                downloadExcelWithResData(res)
              }
            })
          } else {
            downloadExcelWithResData(res)
          }
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      } else if (command === 'pushData') {
        this.$confirm('是否把员工数据同步到市政通系统', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
              hrmEmployeePushDataByIdsAPI(this.selectionList.map(item => item.employeeId))
                  .then(res => {
                    this.$message({
                      type: 'success',
                      message: '推送成功'
                    })
                  })
                  .catch(() => {
                  })
            })
            .catch(() => {

            })
      }
    },

    formChange(item, index, value, valueList, editForm) {
      if ((this.formAddType === 'change-post' || this.formAddType === 'change-level') && item.field == 'changeType') {
        if (value == 7) {
          editForm.changeReason = 4
        } else {
          editForm.changeReason = 1
        }
        this.formAddFields = changePostModel.fieldsFunc(value, this.handleRowData.status)
      } else if (this.formAddType === 'leave' && item.field == 'quitType') {
        if (value == 1) {
          editForm.quitReason = 1
        } else if (value == 2) {
          editForm.quitReason = 11
        } else if (value == 3) {
          editForm.quitReason = ''
        }
        this.formAddRules = employeePost.getRules(editForm)
        this.formAddFields = employeePost.getFields(editForm)
      }
    },

    /**
     * 头部更多操作
     */
    headerMoreHandleClick(command) {
      if (command == 'export') {
        this.loading = true
        const params = {
          employeeName: this.search,
          status: this.tabType
        }

        for (const key in this.filterObj) {
          params[key] = this.filterObj[key]
        }

        for (const key in this.queryParams) {
          params[key] = this.queryParams[key]
        }

        hrmEmployeeExportAPI(params).then(res => {
          // 获取响应头中的密码
          const password = res.headers["content-description"]
          if (password) {
            this.$alert(`导出文件的密码为: ${password}`, '导出提示', {
              confirmButtonText: '确定',
              callback: () => {
                downloadExcelWithResData(res)
              }
            })
          } else {
            downloadExcelWithResData(res)
          }
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      } else if (command == 'import') {
        this.$wkImport.import('hrm', {
          ownerSelectShow: false,
          repeatRuleShow: false,
          importRequest: hrmEmployeeUploadExportAPI, // 导入请求
          templateRequest: hrmEmployeeDownloadExportAPI, // 模板请求
          userInfo: this.userInfo
        })
      } else if (command === 'employeeSync' || command === 'postSync' || command === 'educationSync' || command === 'workSync') {

        let message = "";
        if (command === 'employeeSync') {
          message = "员工基本信息"
        } else if (command === 'postSync') {
          message = "员工岗位信息"
        } else if (command === 'educationSync') {
          message = "员工学历信息"
        } else if (command === 'workSync') {
          message = "员工工作信息"
        }

        this.$confirm('是否把' + message + '数据同步到国资委人资管理系统', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // 显示全局loading
          const loading = this.$loading({
            lock: true,
            text: '正在推送数据...',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          })

          let request = null
          if (command === 'employeeSync') {
            request = hrmEmployeeGzwEmployeeSyncAPI
          } else if (command === 'postSync') {
            request = hrmEmployeeGzwPostSyncAPI
          } else if (command === 'educationSync') {
            request = hrmEmployeeGzwEducationSyncAPI
          } else if (command === 'workSync') {
            request = hrmEmployeeGzwWorkSyncAPI
          }
          request().then(res => {
            this.$message({
              type: 'success',
              message: '推送成功'
            })
          }).catch(() => {
            this.$message({
              type: 'error',
              message: '推送失败'
            })
          }).finally(() => {
            loading.close()
          })
        }).catch(() => {
        })
      }
    },

    /**
     * 获取行操作
     */
    getRowDropdownItems(data) {
      // if ([90, 93].includes(data.entryStatus)) {
      //   return []
      // }
      const dropdownItems = []
      dropdownItems.push({ label: '查看履历', command: 'Resume', icon: 'wk wk-employees' })
      // 入职状态 1 在职 2 待入职 3 待离职 4 离职
      if (data.entryStatus == 2) {
        // 确认入职 操作
        if (this.employeeAuth.confirmEntry) {
          dropdownItems.push({
            label: '确认入职',
            command: 'confirm',
            icon: 'wk wk-activation'
          })
        }
      } else if (data.entryStatus == 4) {
        // 已离职 操作
        if (this.employeeAuth.againOnboarding) {
          dropdownItems.push({
            label: '再入职',
            command: 'again',
            icon: 'wk wk-approval-17'
          })
        }
        // 非已离职 待入职 操作
        if (data.postStatus === '在岗'){
          dropdownItems.push({ label: '职位层级调整', command: 'post-adjust', icon: 'el-icon-s-custom' })
          if (this.employeeAuth.changePost) {
            //调动审批中，不能再次操作
            if (data.entryStatus !== 92) {
              dropdownItems.push({
                label: '人员调动',
                command: 'change-post',
                icon: 'wk wk-employees'
              })
            }
          }
          dropdownItems.push({
            label: '办理离职',
            command: 'leave',
            icon: 'wk wk-approval-16'
          })
          if (data.status == 1 || data.status == 2) {
            if (this.employeeAuth.setInsured) {
              dropdownItems.push({
                label: '参保方案',
                command: 'security',
                icon: 'wk wk-approval-9'
              })
            }
          }
        }
      } else {
        // 试用状态操作
        if (data.status == 2) {
          if (this.employeeAuth.become) {
            dropdownItems.push({
              label: '办理转正',
              command: 'official',
              icon: 'wk wk-transfer'
            })
          }
        }

        if (data.postStatus != '离职') {
          // 非已离职 待入职 操作
          if (this.employeeAuth.changePost) {
            //调动审批中，不能再次操作
            if (data.entryStatus !== 92) {
              dropdownItems.push({
                label: '人员调动',
                command: 'change-post',
                icon: 'wk wk-employees'
              })
            }
          }
          // if (this.employeeAuth.promotion) {
          //   dropdownItems.push({
          //     label: '晋升/降级',
          //     command: 'change-level',
          //     icon: 'wk wk-approval-12'
          //   })
          // }
          // 全职操作
          if (data.status == 1 || data.status == 2) {
            if (this.employeeAuth.setInsured) {
              dropdownItems.push({
                label: '参保方案',
                command: 'security',
                icon: 'wk wk-approval-9'
              })
            }
          }
        }

        // 3 待离职
        if (data.entryStatus == 3) {
          if (this.employeeAuth.cancelLevel) {
            dropdownItems.push({
              label: '放弃离职',
              command: 'give-up-leave',
              icon: 'wk wk-reset'
            })
          }
        } else {
          if (data.postStatus != '离职') {
            dropdownItems.push({ label: '职位层级调整', command: 'post-adjust', icon: 'el-icon-s-custom' })
            if (this.employeeAuth.leave) {
              dropdownItems.push({
                label: '办理离职',
                command: 'leave',
                icon: 'wk wk-approval-16'
              })
            }
          }
        }
      }
      //if (data.postLevel != '员工') { // 非员工层级才有
      dropdownItems.push({
        label: '干部任免表',
        command: 'JobPositionTable',
        icon: 'wk wk-employees'
      })
      // }
      // dropdownItems.push({
      //   label: '删除',
      //   command: 'delete',
      //   icon: 'wk wk-reset'
      // })

      // 1 和 2 是 全职    不是15的是在职
      // 实习 调整部门/岗位、晋升/降级 办理离职 删除
      // 试用 办理转正 办理离职 调整部门/岗位 晋升/降级 删除 2
      // 待离职 调整离职信息 放弃离职 删除 调整部门/岗位、晋升/降级 13
      // 正式 办理离职 调整部门/岗位 晋升/降级 删除 1
      // 已离职 再入职 删除 15
      return dropdownItems
    },

    getRowDropdownShow(data) {
      if ([90, 93].includes(data.entryStatus)) {
        return false
      }
      // 入职状态 1 在职 2 待入职 3 待离职 4 离职
      if (data.entryStatus == 2) {
        // 确认入职 操作
        if (this.employeeAuth.confirmEntry) {
          return true
        }
      } else if (data.entryStatus == 4) {
        // 已离职 操作
        if (this.employeeAuth.againOnboarding) {
          return true
        }
        if (data.postStatus === '在岗'){
          return true
        }
      } else {
        // 试用状态操作
        if (data.status == 2) {
          if (this.employeeAuth.become) {
            return true
          }
        }

        // 非已离职 待入职 操作
        if (this.employeeAuth.changePost) {
          return true
        }

        if (this.employeeAuth.promotion) {
          return true
        }

        // 全职操作
        if (data.status == 1 || data.status == 2) {
          if (this.employeeAuth.setInsured) {
            return true
          }
        }

        // 3 待离职
        if (data.entryStatus == 3) {
          if (this.employeeAuth.cancelLevel) {
            return true
          }
        } else {
          if (this.employeeAuth.leave) {
            return true
          }
        }
      }

      // dropdownItems.push({
      //   label: '删除',
      //   command: 'delete',
      //   icon: 'wk wk-reset'
      // })

      // 1 和 2 是 全职    不是15的是在职
      // 实习 调整部门/岗位、晋升/降级 办理离职 删除
      // 试用 办理转正 办理离职 调整部门/岗位 晋升/降级 删除 2
      // 待离职 调整离职信息 放弃离职 删除 调整部门/岗位、晋升/降级 13
      // 正式 办理离职 调整部门/岗位 晋升/降级 删除 1
      // 已离职 再入职 删除 15
      return false
    },

    async handleTypeClick(command, data) {
      // 行编辑信息
      let res = await hrmEmployeeDetailByEmpIdAPI(data.employeeId);
      if (res.data){
        data = res.data
      }
      this.handleRowData = data
      if (command === 'leave') {
        this.formAddType = command
        this.formAddForm = {
          quitType: 1,
          quitReason: 1
        }
        this.formAddRules = employeePost.getRules(this.formAddForm)
        this.formAddFields = employeePost.getFields(this.formAddForm)
        this.formAddDialogShow = true
      } else if (command === 'official') {
        this.formAddType = command
        this.formAddForm = {
          newDept: data.deptId || '',
          newParentId: data.parentId || '',
          newPost: data.post || '',
          becomeTime: data.becomeTime,
          changeType: 4 // 变动类型 4 转正 5调岗 6晋升 7降级 8转为全职员工
        }
        this.formAddRules = officialModel.rules
        this.formAddFields = officialModel.fields
        this.formAddDialogShow = true
      } else if (command === 'again') {
        this.handleRowData = data
        this.createType = 'again'
        this.isCreate = true
      } else if (command === 'change-post' || command === 'change-level') {
        this.formAddType = command
        this.formAddForm = {
          changeType: command === 'change-post' ? 5 : 6,
          changeReason: 1,
          oldDept: data.deptId || '',
          newDept: '',
          oldOrg: data.orgId || '',
          newOrg: '',
          oldPost: data.jobTitle || '',
          newPost: '',
          oldPostLevel: data.jobLevel || '',
          newPostLevel: '',
          oldWorkAddress: data.workAddress || '',
          newWorkAddress: '',
          entryTime: data.entryTime || ''
        }
        this.formAddRules = changePostModel.rules
        // 只有员工的“工作性质”为“实习、兼职”时，才可以“转全职员工”
        this.formAddFields = changePostModel.fieldsFunc(this.formAddForm.changeReason, data.status)
        this.formAddDialogShow = true
      } else if (command === 'give-up-leave') {
        this.giveUpLeaveShow = true
        // this.$confirm('确定要放弃离职吗？', '提示', {
        //   confirmButtonText: '确定',
        //   cancelButtonText: '取消',
        //   type: 'warning'
        // })
        //   .then(() => {
        //     hrmEmployeePostDeleteLeaveAPI(data.employeeId)
        //       .then(res => {
        //         this.$message({
        //           type: 'success',
        //           message: '操作成功'
        //         })
        //         this.getTabsNum()
        //         this.getList()
        //       })
        //       .catch(() => {})
        //   })
        //   .catch(() => {})
      } else if (command === 'security') {
        this.updateSchemeType = 1
        this.selectionList = [data]
        this.updateSchemeDialogShow = true
      } else if (command === 'confirm') {
        this.handleRowData = data
        this.createType = 'confirm'
        this.isCreate = true
      } else if (command === 'Resume') {
        this.showPreview = true
        this.handleRowData = data
        this.wordType = 1
        this.fileOperate(1, data)
      } else if (command === 'JobPositionTable') {		// 干部任免表
        this.showPreview = true
        this.handleRowData = data
        this.wordType = 2
        this.fileOperate(4, data)
      } else if (command === 'post-adjust') {
        this.formAddType = command
        this.formAddForm = {
          oldPostLevel: data.jobLevel || '',
          newPostLevel: '',
        }
        this.formAddRules = changePostLevelModel.rules
        this.formAddFields = changePostLevelModel.fieldsFunc()
        this.formAddDialogShow = true
      }
    },
    /**
   * 关于文件的操作，1是展示履历图片，2是导出word文档，3是导出PDF文档 4.干部任免表
   */
    fileOperate(type, data) {
      var datax = {}
      console.log(data)
      datax.name = data.employeeName

      datax.gender = employeeModel.sexValue[data.sex]		// 性别后续要添加翻译

      datax.birthday = data.dateOfBirth + `(${data.age}岁)`
      datax.birthday1 = !data.dateOfBirth ? '暂无' : data.dateOfBirth.substring(0, 4) + data.dateOfBirth.substring(5, 7) + '(' + data.age + ')'
      datax.idCard = data.idNumber

      // datax.startWorkTime = "";	//参加工作时间，暂时没有
      datax.ethnic = data.nation
      datax.nativePlace = data.nativePlace
      datax.height = data.height
      datax.weight = data.weight
      datax.health_name = employeeModel.healthValue[data.health]
      datax.marriage_name = employeeModel.marriageValue[data.marriage]		// 婚姻状况后续要添加翻译
      datax.home_place = data.address

      datax.phone = data.emergePhone
      datax.org_name = data.orgName			// 任职机构全称
      datax.deptName = data.deptName
      datax.job_title = data.jobTitle
      datax.job_level = data.jobLevel
      datax.entry_time = data.companyAgeStartTime
      datax.start_time = data.entryTime
      datax.status_name = employeeModel.statusValue[data.status]			// 员工状态，后续要添加翻译
      datax.entry_channel = data.channelId ? data.channelId : ""				//入职渠道
      datax.language_level_name = data.languageLevel
      datax.interest_name = ''		// 兴趣爱好，暂时没有
      datax.driver_license_name = data.driverLicense
      datax.emergencyContactPhone = data.emergeContact + '  ' + data.emergePhone
      const imgSize = {
        imgPath: [300, 300],
        imgPath1: [1100, 500]
      }
      var wbdata = data

      hrmEmployeePersonalInfoAPI(data.employeeId)

        .then(res => {
          const data = res.data || {}
          data.information.forEach(item => {
            if (item.fieldName == 'pol_id') { // 政治面貌
              datax.politic = item.fieldValueDesc		// 政治面貌暂时没有
            } else if (item.fieldName == 'pol_time') {	// 入党时间
              datax.polTime = item.fieldValueDesc		// 入党日期，暂时没有
            } else if (item.fieldName == 'nation') {
              datax.ethnic = item.fieldValueDesc
            } else if (item.fieldName == 'native_place') {
              datax.nativePlace = item.fieldValueDesc
            } else if (item.fieldName == 'height') {
              datax.height = item.fieldValueDesc
            } else if (item.fieldName == 'weight') {
              datax.weight = item.fieldValueDesc
            } else if (item.fieldName == 'health_name') {
              datax.health_name = item.fieldValueDesc
            } else if (item.fieldName == 'marriage_name') {
              datax.marriage_name = item.fieldValueDesc
            } else if (item.fieldName == 'home_place') {
              datax.home_place = item.fieldValueDesc
            } else if (item.fieldName == 'birth_place') {
              datax.birth_place = item.fieldValueDesc
            } else if (item.fieldName == 'home_phone') {
              datax.home_phone = item.fieldValueDesc
            } else if (item.fieldName == 'highest_education') {
              datax.highest_education = item.fieldValueDesc
            } else if (item.fieldName == 'highest_tech_level') {
              datax.highest_tech_level = item.fieldValueDesc
            } else if (item.fieldName == 'language_level_name') {
              datax.language_level_name = item.fieldValueDesc
            } else if (item.fieldName == 'interest_name') {
              datax.interest_name = item.fieldValueDesc
            } else if (item.fieldName == 'driver_license_name') {
              datax.driver_license_name = item.fieldValueDesc
            } else if (item.fieldName == 'join_work_time') {
              datax.join_work_time = item.fieldValueDesc
            } else if (item.fieldName == 'speciality') {
              datax.speciality = item.fieldValueDesc
            } else if (item.fieldName == 'mobile') {
              datax.mobile = item.fieldValueDesc
            }
          })
          data.communicationInformation.forEach(item => {
            if (item.fieldName == 'emergencyContactPhone') {
              datax.emergencyContactPhone = item.fieldValueDesc
            }
          })
          datax.education_list = data.educationExperienceList || []
          console.log(data.educationExperienceList)
          datax.education_list.forEach((item, index) => {
            datax.witness = item.witness ? item.witness : ""
            item.education_name = educationModel.educationValue[item.education]
            if (index == datax.education_list.length - 1) {
              datax.education_name = item.education_name ? item.education_name : ""
              datax.graduateSchool = (item.graduateSchool + item.major)
            }
          })
          const hrmEmployeeContacts = data.hrmEmployeeContacts || []
          var list = []
          hrmEmployeeContacts.forEach(item1 => {
            var obj = {}
            item1.information.forEach(item2 => {
              if (item2.fieldName == 'relation') {		// 成员关系
                obj.family_relationship = item2.fieldValueDesc
              } else if (item2.fieldName == 'contacts_name') {		// 成员姓名
                obj.family_name = item2.fieldValueDesc
              } else if (item2.fieldName == 'contacts_work_unit') {		// 工作单位
                obj.family_work_unit = item2.fieldValueDesc
              } else if (item2.fieldName == 'contacts_post') {		// 职务
                obj.family_post = item2.fieldValueDesc
              } else if (item2.fieldName == 'date_of_birth') {
                obj.date_of_birth = item2.fieldValueDesc
              } else if (item2.fieldName == 'political_outlook') {
                obj.political_outlook = item2.fieldValue
              } else if (item2.fieldName == 'contacts_phone') {
                obj.family_phone = item2.fieldValue ? item2.fieldValue : ""
              }
            })
            list.push(obj)
          })
          datax.family_list = list
          datax.employee_technical = data.technicalList || []
          datax.employee_workexperience = data.workExperienceList || []
          //头像
          const employeeAccountInfo = data.employeeAccountInfo || {}
          datax.imgUrl = employeeAccountInfo.img;
          datax.realName = employeeAccountInfo.realname ? employeeAccountInfo.realname : data.employeeName;
          if (type == 1) {			// 弹窗展示
            getWordImage(
              '../../../../static/resumeTemplate.docx',
              datax,
              imgSize,
              this.$refs.file
            )
          } else if (type == 2) { // 导出文档
            if (this.wordType === 1) {
              exportWordImage('../../../../static/resumeTemplate.docx', datax, wbdata.employeeName, imgSize)
            } else if (this.wordType === 2) {
              exportWordImage('../../../../static/JobPositionTable1.docx', datax, wbdata.employeeName, imgSize)
            }
          } else if (type == 3) {
            exportPdf(
              '#pdfDom',
              wbdata.employeeName
            )
          } else if (type == 4) {
            getWordImage(
              '../../../../static/JobPositionTable1.docx',
              datax,
              imgSize,
              this.$refs.file
            )
          }
        })
        .catch(() => {
          console.log('查询详情网络失败====')
        })
    },
    /**
     * 列表点击
     */
    handleRowClick(row, column, event) {
      if (this.detailAuth && column.property == 'employeeName') {
        this.rowID = row.employeeId
        this.showDview = true
      }
    },

    /**
     * 勾选操作
     */
    handleSelectionChange(val) {
      this.selectionList = val // 勾选的行
      this.tableHeight = document.documentElement.clientHeight - (this.selectionList.length > 0 ? 395 : 345)
    },

    /**
     * 勾选操作
     */
    formAddPass() {
      this.$refs.formAdddialog.loading = true
      this.formAddForm.employeeId = this.handleRowData.employeeId
      let request = null
      if (this.formAddType === 'leave') {
        request = hrmEmployeePostAddLeaveAPI
      } else if (this.formAddType === 'official') {
        request = hrmEmployeeSetBecomeAPI
      } else if (this.formAddType === 'change-post') {
        request = hrmEmployeeSetChangePostAPI
      } else if (this.formAddType === 'change-level') {
        request = hrmEmployeeSetPromotionAPI
      } else if (this.formAddType === 'post-adjust') {
        request = hrmEmployeePostLevelAuditAPI
      }

      request(this.formAddForm).then(res => {
        this.$refs.formAdddialog.loading = false
        this.$message.success(`${this.formAddTitle}成功`)
        this.formAddDialogShow = false
        this.getTabsNum()
        this.getList()
      }).catch(() => {
        this.$refs.formAdddialog.loading = false
      })
    },

    fieldSetSave(fields) {
      this.fieldSetLoading = true
      fields.forEach((item, index) => {
        item.isHide = item.check ? 0 : 1
        item.sort = index
      })

      hrmEmployeeFieldUpdateConfigAPI(fields)
        .then(res => {
          this.$message.success('操作成功')
          this.getFieldList()
          this.fieldSetLoading = false
        })
        .catch(() => {
          this.fieldSetLoading = false
        })
    },

    handleHeaderDragend(newWidth, oldWidth, column, event) {
      if (column.property) {
        const currentItem = this.showFieldList.find(item => item.fieldName == column.property)
        if (currentItem) {
          hrmEmployeeFieldUpdateWidthAPI({
            width: newWidth,
            fieldId: currentItem.fieldId
          })
            .then(res => {
            })
            .catch(() => { })
        }
      }
    },

    /**
     * @description: 通过路由等路由携带的需要处理的事情
     * @return {*}
     */
    initTask() {
      const { query } = this.$route
      if (query.event === 'detail') {
        this.rowID = query.id
        this.showDview = true
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.employee-index {
  .xr-header {
    margin-bottom: 20px;

    ::v-deep .xr-header__ft {
      top: 0;
      line-height: 34px;
    }
  }

  ::v-deep.xr-table-header {
    border-bottom: 1px solid $--border-color-base;

    .xr-table-header__body {
      padding: 0;
    }
  }

  .search-button {
    border: none;

    &.is-select {
      color: white;
      background: $--color-primary;
    }
  }

  ::v-deep .el-tabs {
    .el-tabs__header {
      margin-bottom: 0;
    }

    .el-tabs__item {
      font-weight: bold;
      color: $--color-text-regular;
    }
  }

  .tab-pane-num {
    display: inline-block;
    height: 18px;
    padding: 0 6px;
    font-size: 12px;
    font-weight: bold;
    line-height: 18px;
    color: $--color-text-regular;
    text-align: center;
    white-space: nowrap;
    background-color: #dfe1e6;
    border: 1px solid #fff;
    border-radius: 10px;
  }

  .table-more {
    cursor: pointer;

    &:hover {
      color: $--color-primary;
    }
  }

  .filter {
    margin-bottom: 8px;

    .wk-border-menu+.wk-border-menu {
      margin-left: 20px;
    }
  }
}

.field-set-wrap {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 99;
}

::v-deep span {
  font-family: "Microsoft YaHei" !important;
}
</style>
